Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Web Accessibility. window.speechSynthesis vs role "alert"

To immediately announce error for control/input I have 2 choices:

  1. append HTMLElement to document with role 'alert' and error-message. NVDA reads alert. [errorMessageHere]

const el = document.createElement('div');
el.setAttribute('role', 'alert');
el.className = 'visually-hidden';
el.textContent = 'Some message here';
document.body.append(el);
.visually-hidden {
  position: absolute;
  height: 1px;
  width: 1px;
  top: 0;
  left: 0;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
}

  1. Use window.speechSynthesis.speak. NVDA announce [errorMessageHere]

const speakObj = new SpeechSynthesisUtterance('Some message here');
window.speechSynthesis.speak(speakObj)

What I really notice that in NVDA you can disable text-to-speech and show speech-viewer. First case will be logged into speech-viewer but 2nd case - not. NVDA directly announce text when NVDA is opened even if text-to-speech is disabled.

I'd prefer to use window.speechSynthesis.speak instead of creating extra HTMLElements per each case when some details/errors must be announced but I'm not sure is it correct alternative of role 'alert' since window.speechSynthesis.speak is not logged by NVDA at all (but only announced).

Could help me to understand what the best way to be announced/read by screen reader ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!